from django.db import models
from dingxiang.utils.models import BaseModel
# Create your models here.

# 大众健康方向
class PublicHealthDirection(BaseModel):
    name = models.CharField(max_length=100, null=True, blank=True, verbose_name='大众健康方向')
    class Meta:
        db_table = 'publicHealth_direction'
        verbose_name_plural = '大众健康方向'

    def __str__(self):
        return self.name

# 大众健康分类
class PublicHealthClassification(BaseModel):
    name = models.CharField(max_length=100, null=True, blank=True, verbose_name='大众健康分类')
    health_direction = models.ManyToManyField(PublicHealthDirection, null=True, blank=True, verbose_name="大众健康方向")
    publicHealth_articles = models.ManyToManyField("PublicHealthArticles", null=True, blank=True, verbose_name="大众健康文章")

    class Meta:
        db_table = 'publicHealth_classification'
        verbose_name_plural = '大众健康分类'

    def __str__(self):
        return self.name

# 大众健康文章
class PublicHealthArticles(BaseModel):
    title = models.CharField(max_length=255, verbose_name="标题", null=True, blank=True)
    content = models.TextField(verbose_name="内容", null=True, blank=True)
    author = models.CharField(max_length=255, verbose_name="作者", null=True, blank=True)
    publish_date = models.DateField(auto_now_add=True, null=True, blank=True, verbose_name="发表日期")
    image = models.ImageField(upload_to='public_health/', null=True, blank=True, verbose_name="图片")

    class Meta:
        db_table = 'publicHealth_articles'
        verbose_name_plural = '大众健康文章'

    def __str__(self):
        return self.name
